﻿// PlugIn1PlugIn.cpp : defines the initialization routines for the plug-in.
//

#include "StdAfx.h"
#include "rhinoSdkPlugInDeclare.h"
#include "PlugIn1PlugIn.h"
#include "Resource.h"

// The plug-in object must be constructed before any plug-in classes derived
// from CRhinoCommand. The #pragma init_seg(lib) ensures that this happens.
#pragma warning(push)//保存当前的编译器警告状态，以便稍后恢复。
#pragma warning(disable : 4073)//禁用特定的编译器警告（警告编号 4073）。
#pragma init_seg(lib)//设置初始化段的顺序，指定初始化代码在库（lib）阶段执行。
#pragma warning(pop)//恢复之前保存的编译器警告状态。

// Rhino plug-in declaration
RHINO_PLUG_IN_DECLARE

// Rhino plug-in name
// Provide a short, friendly name for this plug-in.
RHINO_PLUG_IN_NAME(L"PlugIn123");//插件的名字（在插件程序中）

// Rhino plug-in id
// Provide a unique uuid for this plug-in.
RHINO_PLUG_IN_ID(L"F78F6AAF-C1E0-49A9-89A7-76D52AB1B97C");//插件的Id

// Rhino plug-in version
// Provide a version number string for this plug-in.
RHINO_PLUG_IN_VERSION(__DATE__ "1.0  " __TIME__)
/*__DATE__ 返回当前编译日期的字符串，格式为 MMM DD YYYY（例如 Feb 15 2025）。

__TIME__ 返回当前编译时间的字符串，格式为 HH:MM:SS（例如 11:07:26）。

字符串拼接：__DATE__ " " __TIME__ 将编译日期和时间拼接成一个字符串，中间用两个空格分隔。*/

// Rhino plug-in description
// Provide a description of this plug-in.
RHINO_PLUG_IN_DESCRIPTION(L"PlugIn123 plug-in for Rhinoceros®");//插件的描述

// Rhino plug-in icon resource id
// Provide an icon resource this plug-in.
// Icon resource should contain 16, 24, 32, 48, and 256-pixel image sizes.
// Rhino 插件图标资源标识符
// 为该插件提供一个图标资源。
// 图标资源应包含 16 像素、24 像素、32 像素、48 像素和 256 像素的图像尺寸。
RHINO_PLUG_IN_ICON_RESOURCE_ID(IDI_ICON);//设置图标

// Rhino plug-in developer declarations
// TODO: fill in the following developer declarations with
// your company information. Note, all of these declarations
// must be present or your plug-in will not load.
//
// Rhino 插件开发人员声明
// TODO：请在以下开发人员声明中填写您的公司信息。请注意，所有这些声明都必须存在，否则您的插件将无法加载。
// When completed, delete the following #error directive.// 完成后，请删除以下 #error 指令。

//#error Developer declarations block is incomplete!//当完成后，删除以下代码行，因为#error指令将阻止项目的构建:

RHINO_PLUG_IN_DEVELOPER_ORGANIZATION(L"My Company Name");
RHINO_PLUG_IN_DEVELOPER_ADDRESS(L"123 Developer Street\r\nCity State 12345-6789");
RHINO_PLUG_IN_DEVELOPER_COUNTRY(L"My Country");
RHINO_PLUG_IN_DEVELOPER_PHONE(L"123.456.7890");
RHINO_PLUG_IN_DEVELOPER_FAX(L"123.456.7891");
RHINO_PLUG_IN_DEVELOPER_EMAIL(L"support@mycompany.com");
RHINO_PLUG_IN_DEVELOPER_WEBSITE(L"http://www.mycompany.com");
RHINO_PLUG_IN_UPDATE_URL(L"http://www.mycompany.com/support");

// The one and only CPlugIn1PlugIn object
static class CPlugIn1PlugIn thePlugIn;

/////////////////////////////////////////////////////////////////////////////
// CPlugIn1PlugIn definition

CPlugIn1PlugIn& PlugIn1PlugIn()
{
	// Return a reference to the one and only CPlugIn1PlugIn object
	return thePlugIn;
}

CPlugIn1PlugIn::CPlugIn1PlugIn()
{
	// Description:
	//   CPlugIn1PlugIn constructor. The constructor is called when the
	//   plug-in is loaded and "thePlugIn" is constructed. Once the plug-in
	//   is loaded, CPlugIn1PlugIn::OnLoadPlugIn() is called. The
	//   constructor should be simple and solid. Do anything that might fail in
	//   CPlugIn1PlugIn::OnLoadPlugIn().

	// TODO: Add construction code here
	// 描述：
//   CPlugIn1PlugIn 构造函数。当插件被加载且“thePlugIn”被构建时，会调用此构造函数。一旦插件被加载，就会调用 CPlugIn1PlugIn::OnLoadPlugIn() 方法。该构造函数应当简单且可靠。在 CPlugIn1PlugIn::OnLoadPlugIn() 方法中可能会发生任何失败的情况，此时构造函数都应能应对。

// TODO：在此添加构造代码
	m_plugin_version = RhinoPlugInVersion();
}

/////////////////////////////////////////////////////////////////////////////
// Required overrides//要求覆盖

const wchar_t* CPlugIn1PlugIn::PlugInName() const
{
	// Description:
	//   Plug-in name display string.  This name is displayed by Rhino when
	//   loading the plug-in, in the plug-in help menu, and in the Rhino
	//   interface for managing plug-ins.

	// TODO: Return a short, friendly name for the plug-in.
	// 描述：
//   插件名称显示字符串。此名称在 Rhino 加载插件时、在插件帮助菜单中以及在用于管理插件的 Rhino 界面中都会显示出来。

// 注意事项：返回插件的一个简短、友好的名称。
	return RhinoPlugInName();
}

const wchar_t* CPlugIn1PlugIn::PlugInVersion() const
{
	// Description:
	//   Plug-in version display string. This name is displayed by Rhino
	//   when loading the plug-in and in the Rhino interface for managing
	//   plug-ins.

	// TODO: Return the version number of the plug-in.
	// 描述：
	// 插件版本显示字符串。此名称会在 Rhino 加载插件时以及在 Rhino 管理插件的界面中显示出来。

	// 待办事项：返回插件的版本号。
	return m_plugin_version;
}

GUID CPlugIn1PlugIn::PlugInID() const
{
	// Description:
	//   Plug-in unique identifier. The identifier is used by Rhino to
	//   manage the plug-ins.

	// TODO: Return a unique identifier for the plug-in.
	// {F78F6AAF-C1E0-49A9-89A7-76D52AB1B97C}
	// 描述：
	//   插件唯一标识符。该标识符由 Rhino 使用以管理插件。

	// TODO：返回插件的唯一标识符。
	// {F78F6AAF-C1E0-49A9-89A7-76D52AB1B97C}
	return ON_UuidFromString(RhinoPlugInId());
}

/////////////////////////////////////////////////////////////////////////////
// Additional overrides

BOOL CPlugIn1PlugIn::OnLoadPlugIn()
{
	// Description:
	//   Called after the plug-in is loaded and the constructor has been
	//   run. This is a good place to perform any significant initialization,
	//   license checking, and so on.  This function must return TRUE for
	//   the plug-in to continue to load.

	// Remarks:
	//    Plug-ins are not loaded until after Rhino is started and a default document
	//    is created.  Because the default document already exists
	//    CRhinoEventWatcher::On????Document() functions are not called for the default
	//    document.  If you need to do any document initialization/synchronization then
	//    override this function and do it here.  It is not necessary to call
	//    CPlugIn::OnLoadPlugIn() from your derived class.

	// TODO: Add plug-in initialization code here.
	return TRUE;
}

void CPlugIn1PlugIn::OnUnloadPlugIn()
{
	// Description:
	//    Called one time when plug-in is about to be unloaded. By this time,
	//    Rhino's mainframe window has been destroyed, and some of the SDK
	//    managers have been deleted. There is also no active document or active
	//    view at this time. Thus, you should only be manipulating your own objects.
	//    or tools here.

	// TODO: Add plug-in cleanup code here.
}
